import * as echarts from '../../../../../../common/ec-canvas/echarts';
import $service from '../../../../../../service'
let AgeChart = null
const app = getApp();

let lineops = []
Component({
  properties: {
    requestId: {
      type: String,
      value: ''
    },
    listData: {
      type: Array,
      value: []
    },
    expressionData: {
      type: Array,
      value: []
    }
  },
  data: {
    ec: {
      onInit: function (canvas, width, height, dpr) {
        AgeChart = echarts.init(canvas, null, {
          width: width,
          height: height,
          devicePixelRatio: dpr // new
        });
        canvas.setChart(AgeChart);
        AgeChart.setOption(getBarOption());
        return AgeChart;
      }
    },
    mainBody: '',
    secondBody: ''
  },
  lifetimes: {
    ready() {
      this.corporeityResult()
    }
  },
  methods: {
    corporeityResult() {
      app.http.corporeityResult({requestId: this.properties.requestId}).then(res => {
        let list = $service.deepClone(res.data.corporeityProbs)
        list.forEach((item) => {
          item.value = item.prob
          item.name = item.cor
        })
        lineops = list
        let mainBody = list[0].cor
        let secondBody = list[1].cor + '、' + list[2].cor
        console.log(mainBody, secondBody)
        this.setData({
          mainBody,
          secondBody
        })
        AgeChart.setOption(getBarOption());
      }).catch(err => {
        console.log(err)
        $service.showToast(err.msg)
      })
    }
  }
})


function getBarOption() {
  return {
    legend: {
      bottom: 10,
      left: 'center'
    },
    series: [{
      type: 'pie',
      radius: ['30', '60%'],
      clockwise: false,
      center: ['50%', '40%'],
      labelLine: {
        smooth: true
      },
      label: {
        fontSize: 15,
        rich: {},
        formatter: '{d}%',
      },
      color: ["#FFF82D", "#0069FF", "#FF8716"],
      data: lineops,
    }, ]

  }
}